import vnode from "./vnode";
/**
 * 低配版h函数，没有重载功能
 * 调用示例：
 * h('div', {}, '文字')
 * h('div', {}, [])
 * h('div', {}, h())
 */
export default function (sel, data, c) {
    //检查参数个数
    if (arguments.length != 3) {
        throw new Error('低配版h函数必须传入三个参数')
    }
    //检查参数c的类型
    if (typeof c == 'string' || typeof c == 'number') {
        return vnode(sel, data, undefined, c, undefined)
    } else if (Array.isArray(c)) {
        let children = []
        for (let i = 0; i < c.length; i++) {
            if (!(typeof c[i] == 'object' && c[i].hasOwnProperty('sel'))) {
                throw new Error('传入的数组参数中有项不是h函数')
            }
            children.push(c[i])
        }
        return vnode(sel, data, children, undefined, undefined)
    } else if (typeof c == 'object' && c.hasOwnProperty('sel')) {
        let children = [c];
        return vnode(sel, data, children, undefined, undefined)
    } else {
        throw new Error('傳入的第三個參數不對')
    }
}